package com.xiaotu.zhouyi.controller;


import com.xiaotu.core.asyncs.AsyncsXiaotu;
import com.xiaotu.result.R;
import com.xiaotu.zhouyi.pojo.entity.GuaSixtyfour;
import com.xiaotu.zhouyi.pojo.entity.TGuaSixtyfour;
import com.xiaotu.zhouyi.service.GuaSixtyfourService;
import com.xiaotu.zhouyi.service.TGuaSixtyfourService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xiaotu
 * @since 2022-01-13
 */
@CrossOrigin
@Api("周易六十四卦")
@RestController
@RequestMapping("/server/zhouyi/guaSixtyfour")
@EnableAsync
public class GuaSixtyfourController {
    @Autowired
    private GuaSixtyfourService guaSixtyfourService;
    @Autowired
    private TGuaSixtyfourService tGuaSixtyfourService;
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private AsyncsXiaotu asyncsXiaotu;
    @GetMapping
    public R getList(){
        List<TGuaSixtyfour> list = ( List<TGuaSixtyfour>)redisTemplate.opsForValue().get("sixtyfours");
        if (list == null){
            list = tGuaSixtyfourService.list();
            //异步存储
            asyncsXiaotu.redisMethod(list,"sixtyfours",60*60L);
            //System.out.println("=========>这里被执行了");
        }
        return R.ok().data("list",list);
    }
    @GetMapping("/{id}")
    public R getById(@ApiParam(value = "id数据",required = true ,example = "1")@PathVariable Integer id){
        GuaSixtyfour byId = guaSixtyfourService.getById(id);
        return  R.ok().data("record", byId);
    }

}
